var addUrl = "/App/AppList/add";//添加地址
var deleteUrl = "/App/AppList/delete";//删除地址
/**
 * 添加应用
 * @param string item ID名
 * @param string applyClassName 应用类名
 */
var AddApply = function(item, applyClassName, applyID) {
	var tds = $("#" + item).find('td');
	var applyImg = $(tds[0]).html();
	var applyName = $(tds[1]).text();
	var applyIntroduction = $(tds[2]).text();
	var addHtml = ["<tr>",
		"<td>" + applyImg + "</td>",
		"<td>" + applyName + "</td>",
		"<td>" + applyIntroduction + "</td>",
		"<td>" + applyClassName + "</td>",
		"<td>已启动</td>",
		"<td><a href='javascript:void();' onclick=" + '"' + "delApply(this, '" + item + "','" + applyID + "');" + '"' + ">删除应用</a></td>",
		"</tr>"
	];
	var html = addHtml.join(',');
	var obj = {
		html: html,
		item: item,
		id: item,
		type:applyID
	};
	General.confirm('确认添加' + applyName + '应用？', null, startAdd, null, obj);
	//  if(confirm('确认添加'+applyName+'应用？')) {
	//      $("#AddList").append(html);
	//      $("#"+item).remove();
	//  }
};
//开始添加
function startAdd(obj) {
	General.showMask();
	var options = obj;
	var url = addUrl;
	var data = {
		"id": obj.id
	};
	var tip = "正在添加应用";
	Common.ajaxPost(options, null, url, data, tip, completeAdd, failAdd);
};
//添加成功
function completeAdd(options, data, status) {
	General.hideMask();
	data=$.parseJSON(data);
	if(data.success){
		General.refresh();
	}else{
		var msg=data.msg+data.sub_msg;
		General.alert(msg);
	}
};
//添加失败
function failAdd() {
	General.hideMask();
	General.alert("添加应用失败");
};




/**
 * 删除应用
 * @param int key 排序号
 * @param int item 应用ID
 * @param int ClassId 类ID
 */
var delApply = function(t, item, ClassId) {
	var tds = $(t).parent().parent().find('td');
	var applyImg = $(tds[0]).html();
	var applyName = $(tds[1]).text();
	var applyIntroduction = $(tds[2]).text();
	var applyClassName = $(tds[3]).text();
	var addHtml = ["<tr id=" + item + ">",
		"<td>" + applyImg + "</td>",
		"<td>" + applyName + "</td>",
		"<td>" + applyIntroduction + "</td>",
		"<td><a href='javascript:void();' onclick=" + '"' + "AddApply('" + item + "', '" + applyClassName + "', '" + ClassId + "');" + '"' + ">添加</a></td>",
		"</tr>"
	];
	var html = addHtml.join(',');
	var obj = {
		html: html,
		tds: tds,
		item: item,
		id: item,
		type:ClassId
	};
	General.confirm('确认删除' + applyName + '应用？', null, startDelete, null, obj);
//	if (confirm('确认删除' + applyName + '应用？')) {
//		$("#" + ClassId + "").append(html);
//		$(tds).remove();
//	}
};
//开始删除
function startDelete(obj) {
	General.showMask();
	var options = obj;
	var url = deleteUrl;
	var data = {
		"id": obj.id
	};
	var tip = "正在删除应用";
	Common.ajaxPost(options, null, url, data, tip, completeDelete, failDelete);
};
//删除成功
function completeDelete(options, data, status) {
	General.hideMask();
	data=$.parseJSON(data);
	if(data.success){
		General.refresh();
	}else{
		var msg=data.msg+data.sub_msg;
		General.alert(msg);
	}
};
//删除失败
function failDelete() {
	General.hideMask();
	General.alert("删除应用失败");
};